package com.fy.fyspace.controller;

import com.fy.fyspace.common.result.R;
import com.fy.fyspace.service.TestUserService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "测试用户大数据查询接口", description = "提供大数据量下的复杂查询演示")
@RestController
@RequestMapping("/testuser")
public class TestUserController {

    @Resource
    private TestUserService testUserService;

    @ApiOperation(value = "按姓名模糊查询用户", notes = "支持分页，name为模糊关键字")
    @GetMapping("/queryByName")
    public R queryByName(@RequestParam String name,
                              @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "20") Integer pageSize) {
        return testUserService.queryByName(name, page, pageSize);
    }

    @ApiOperation(value = "按年龄区间查询用户", notes = "支持分页，minAge/maxAge为闭区间")
    @GetMapping("/queryByAgeRange")
    public R queryByAgeRange(@RequestParam Integer minAge,
                                  @RequestParam Integer maxAge,
                                  @RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "20") Integer pageSize) {
        return testUserService.queryByAgeRange(minAge, maxAge, page, pageSize);
    }

    @ApiOperation(value = "按性别和爱好模糊查询用户", notes = "支持分页，hobby为模糊关键字")
    @GetMapping("/queryBySexAndHobby")
    public R queryBySexAndHobby(@RequestParam String sex,
                                     @RequestParam String hobby,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "20") Integer pageSize) {
        return testUserService.queryBySexAndHobby(sex, hobby, page, pageSize);
    }

    @ApiOperation(value = "统计各年龄段用户数量", notes = "返回每个年龄的用户数量，按数量降序排序")
    @GetMapping("/statisticsByAge")
    public R statisticsByAge() {
        return testUserService.queryStatistics();
    }
} 